﻿/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.bourre.commands.AbstractSyncCommand;
import com.bourre.commands.ISyncCommand;
import com.bourre.events.IEvent;
import com.bourre.log.PixlibStringifier;
import com.bourre.transitions.IFrameListener;
import com.kairos.engine.RTBeacon;
import com.kairos.engine.RTEvent;
import com.kairos.commands.IntervalRT;


import com.prizee.log.AIRLoggerAS2;

/**
 * A {@code TimeoutRT} object work as a call of the {@code setTimeout} method
 * but can be paused, restart, and synchronized with the whole application
 * run dint {@code RTBeacon}.
 * 
 * <p>Because of scope issues you have to specify the function scope when
 * you create a new {@code TimeoutRT} object.</p>  
 * 
 * <p>{@code TimeoutRT} extends {@code IntervalRT} so you can use all its method
 * with the {@code TimeoutRT} object.</p>
 * 
 * <p>{@code TimeoutRT} implements the {@code ISyncCommand} interface, so you could
 * use it with a {@code StepCommandManager}, or in your {@code FrontController}.</p>
 * 
 * @author	Cédric Néhémie
 * @example	import com.kairos.commands.TimeoutRT;
 * 
 * var myTimeout : TimeoutRT = new TimeoutRT ( this, myFunction, 1000, "someParam" );
 * myTimeout.start (); 
 */
class com.kairos.commands.TimeoutRT extends IntervalRT implements IFrameListener, ISyncCommand
{
	/**
	 * Create a new {@code TimeoutRT} object.
	 * 
	 * <p>You have to call the {@link #execute} or {@link #start} method to start
	 * the Timeout run.</p>
	 * 
	 * <p>You can specify additionnal arguments to pass to the function.</p>
	 *	
	 * @param	o	The object in witch scope the function is run.
	 * @param	f	The function to call.
	 * @param	d	The delay of the Timeout.
	 * @example	var myTimeout : TimeoutRT = new TimeoutRT ( this, myFunction, 1000 );
	 * @example	var myTimeout : TimeoutRT = new TimeoutRT ( this, myFunction, 1000, "someParam" );
	 */	
	public function TimeoutRT ( o, f : Function, d : Number )
	{
		super( o, f, d, 1 );
		setArguments.apply( this, arguments.splice( 3 ) );
	}

	/**
	 * Return the string representation of the object 
	 */	
	public function toString() : String
	{
		return PixlibStringifier.stringify( this );
	}
}
